<template>
  <div>
      <Table 
      :tableData="tableData"
      :tableHead="tableHead"
      @stateChange="stateChange"
      @updateNotice="updateNotice"
      @deleteNotice="deleteNotice"
      @textView="textView"
      @handleSelectionChange="handleSelectionChange"
      />
     <Pagination
      :total="total"
      @changePage="getTime"
      />

  </div>
</template>
<script>
import axios from 'axios'
import Pagination from '../components/common/Pagination.vue'
import Table from '../components/common/fengzhuang.vue'
export default {
    components:{
        Table,
        Pagination
    },
    data(){
        return{
               total:0,
               formline: {
               user: '',
               region: '',
               key:'',        //否	string	搜索关键字
               address:'',	      //否	string	地址
               tel:'',      //否	string	联系电话
               begindate:'',    //否	string	查询开始日期
               enddate:'',	        //否	string	查询截止日期
               state:'',     //否	int	维修状态
               type:'',     	//否	int	维修类型
               userid:'',    	//否	int	居民id
               page:1,        	//否	int	当前页码
               psize:5          //否	int	每页显示多少条
        },
            tableData:[],
            tableHead:[
                {
                    label:'ID',
                    prop:'id'
                },
                 {
                    label:'公告标题',
                    prop:'content',
                    type:'isClick'
                },
                  {
                    label:'状态',
                    prop:'state',
                    type:'switch'
                },
                   {
                    label:'操作',
                    type:'button',
                    button:{
                      update:true,
                      delete:true
                    }
                },
                 {
                    label:'添加人',
                    prop:'edituser',
                    type:'isClick'
                },
                {
                    label:'头像',
                    prop:'picture',
                    type:'img',
                    formatter:(row,prop)=>{
                      let defimg='https://tse1-mm.cn.bing.net/th/id/R-C.65a32f211b1e8a3a1540d96953618005?rik=KRp9q8QRwCuHhA&riu=http%3a%2f%2fscimg.jianbihuadq.com%2f202007%2f20200707170327105.jpg&ehk=YqgAZ9O6rbO1vgEfVvcbDxMWjtnbEFOrT%2baLGamBssg%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1'
                      return !prop ?defimg
                    :this.$config.baseUrl+'/upload/'+prop
                    
                    }
                },
                  {
                    label:'图片',
                    prop:'images',
                    type:'img',
                    imgClick:true,
                    formatter:(row,prop)=>{
                    const images =prop.map(item=>this.$config.baseUrl+item.url)
                    // console.log(images)
                    return{
                      url  :images[0],
                      images
                    }
                    }
                },
            ]
        }
    },
    mounted(){
        this.getTime()
    },
    methods:{
      handleSizeChange (val) {
      this.formline.psize = val
      this.getTime()
    },
    handleCurrentChange (val) {
      this.formline.page = val
       this.getTime()
    },
      handleSelectionChange (val) {
        console.log(val)
      },
      stateChange(data){
        console.log('stateChange',data);
      },
       updateNotice(data){
        console.log('updateNotice',data);
      },
      deleteNotice(data){
        console.log('deleteNotice',data);
      },
      textView(data){
        console.log('textView',data);
      },
    getTime(param){
      console.log(param,'param');
        const token =sessionStorage.getItem('token')
        const parms={
          Authorization:token
        }
        axios.get('http://estate.eshareedu.cn/estate/api/repairs/list',{headers:parms,params:Object.assign(this.formline,param)}).then(res=>{
          console.log(res,'res');
          const{errCode,errMsg}=res.data
          if (errCode==10000) {
            console.log(res,'列表');
            this.tableData=res.data.data.list
            this.total=res.data.data.counts
          }else{
            console.log(errMsg);
          }
        })
      }
    }
    
}
</script>

<style>

</style>